<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<div id="cc_products" class="easyui-layout" style="width:100%;height:100%;" fit="true">
	<div data-options="region:'north',title:'商品管理',split:true" style="height:70px;background-color:#e6edfd;">
    	<form action="" id="searchForm" name="searchForm">
    	<table class="screen">
			<tr>
				<td class="screen-n"><span>商品编码|名称|拼音</span></td>
				<td class="screen-n">
					<input type="text" id="search_productName" class="screen-input" onkeydown="pms.kd13('initProducts')">
				</td>
				<td class="screen-n"><span>品牌</span></td>
				<td class="screen-n">
					<input type="text" id="s_brand" class="screen-input"  onkeydown="pms.kd13('initProducts')">
				</td>
				<td class="screen-n"><span>供应商</span></td>
				<td class="screen-n">
					<input type="text" id="s_providerCode" class="screen-input"  onkeydown="pms.kd13('initProducts')">
				</td>
				<td class="screen-n"><span>厂家</span></td>
				<td class="screen-n">
					<input type="text" id="s_producingName" class="screen-input"  onkeydown="pms.kd13('initProducts')">
				</td>
				<td class="screen-n">
					<input type="button" class="button" value="查询" onclick="initProducts()">
					<input type="button" class="button" value="重置" onclick="pms.resetForm('searchForm')" >
				</td>
			</tr>
		</table>
		</form>
    </div>
    <div data-options="region:'center',split:true" style="width: 100%;height: 100%">
		<table id="tableGrid"></table>
	</div>
</div>  
<script>
var toolbar = [{
	text:'新增商品',
    iconCls:'icon-add',
    handler:function(){
    	openProductAddWindow();
    }
}];
var productsTable;
$(function(){
	initProducts();
});

function initProducts(){
	productsTable = $('#tableGrid').pDataGrid({
		toolbar:toolbar,
		 columns:[[
		          	 {field:'action',title:'操作',align:'center',formatter:function(value,row,index){
						return '<a href="#"  onclick="openProductUpdateWindow('+row.productCode+')">修改</a> | <a href="#" onclick="deleteProduct('+row.productCode+','+index+')">删除</a> ';
		          		}},
		              {field:'productCode',title:'商品编号',align:'center'},
		              {field:'productName',title:'商品名称',align:'center'},
		              {field:'spell',title:'拼音码',align:'center'},
		              {field:'productSpec',title:'规格',align:'center'},
		              {field:'packingUnit',title:'包装',align:'center'},
		              {field:'salePrice',title:'价格',align:'center'},
		              {field:'retailPrice',title:'建议价',align:'center'},
		              {field:'providerName',title:'供货商',align:'center'},
		              {field:'producingArea',title:'产地',align:'center'},
		              {field:'producingName',title:'生产厂家',align:'center'},
		              {field:'authorizeNumber',title:'批准文号',align:'center'},
		              {field:'barcode',title:'条码',align:'center'},
		              {field:'brand',title:'品牌',align:'center'},
		              {field:'stockQuantity',title:'库存',align:'center'},
		              {field:'storeCondition',title:'存储条件',align:'center'},
		              {field:'status',title:'状态',align:'center'}
		          ]],
		    url:'<c:url value="/products/searchProducts.do"/>',  
		    pagination:true,
		    pageSize:20,
		    fitColumns:'false',
		    queryParams:{
				"productName":$('#search_productName').val(),
				"brand":$("#s_brand").val(),
				"providerCode":$("#s_providerCode").val(),
				"producingName":$("#s_producingName").val()
		    }
	}); 
}

function openProductAddWindow(){
	$.pmsDialog({
		id:"w_product_add",
		title:'新增商品',
		method:'post',
		href:'<c:url value="/views/product/product_add.jsp"/>',
		width:800,
	});
}

function openProductUpdateWindow(code){
	var params = {"productCode":code}
	$.pmsDialog({
		id:"w_product_update",
		title:'修改商品',
		method:'post',
		params:params,
		href:'<c:url value="/views/product/product_update.jsp"/>',
		width:800,
	});
}

function deleteProduct(code,i){
	if(confirm("确定删除?")){
		var param = {"productCode":code};
		$.pmsAjax({
			url:'<c:url value="/products/deleteProduct.do"/>',
			data:param,
			success:function(data){
				if(data.resultCode=="200"){
					alertShow("删除成功");
					productsTable.removeRow(i);
				}else{
					alertError(data.resultMessage);
				}
			}
		});
	}
}

</script>
